const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();

// 查询数据库集合云函数入口函数
// 查找昵称
exports.main = async (event, context) => {
  // 返回数据库查询结果
  let isOpen = await db.collection('userList').where({
    openid: event.openid,
  }).get();
  if (isOpen.data.length == 0) {
    await db.collection('userList').add({
      data: {
        openid: event.openid,
        creatTime: event.creatTime,
      }
    });
  }
  return {
    isOpen
  }
};
